<include file="../header" />
<body class="J_scroll_fixed">
    <script src="http://res.wx.qq.com/open/js/jweixin-1.0.0.js"></script>
    <script charset="utf-8" src="http://map.qq.com/api/js?v=2.exp&key=FO5BZ-2AC2G-ACAQV-I5BD3-YX65K-76BUB"></script>
    <script src="http://open.map.qq.com/apifiles/v1.0/app.js?v=1.0.131203.1" type="text/javascript"></script>
    <script type="text/javascript">
        $(document).ready(function () {
            var flag = $('input[name=flag]').val();
             $('#courseTypeDiv').attr("style", "display:none;");
            if(flag!=null&&flag=='existed'){
                $('#courseTypeDiv').show();
                $('#checkCoachDiv').show();
                
                $('input[name=headImageUrl]').attr("readOnly", true);
                $('input[name=mobile]').attr("readOnly", true);
                $('input[name=idcardNumber]').attr("readOnly", true);
                $('select[name=gender]').attr("disabled", "disabled");
                layer.msg('该公开课存在,请核对课程或更改课程信息!');
            }

            $('input.checkCoach').click(function () {

                var coachName = $('input[name=coachName]').val();
                var shopId = $('input[name=shopId]').val();

                $.ajax({
                    type: "post",
                    url: "{:U('publicCourse/checkCoach')}",
                    data: {coachName: coachName, shopId: shopId},
                    dataType: "json",
                    success: function (data) {

                        if (data['errCode'] === 500) {
                            layer.msg('请添加该教练信息!');
                            $('#checkCoachDiv').show();
                            $('#courseTypeDiv').show();

                            $('input[name=headImageUrl]').val("");
                            $('input[name=mobile]').val("");
                            $('input[name=idcardNumber]').val("");

                            $('input[name=headImageUrl]').attr("readOnly", false);
                            $('input[name=idcardNumber]').attr("readOnly", false);
                            $('input[name=mobile]').attr("readOnly", false);
                            $('select[name=gender]').removeAttr("disabled");

                        } else {
                            layer.msg('该教练存在,请核对教练信息!');
                            $('#checkCoachDiv').show();
                            $('#courseTypeDiv').show();

                            $('input[name=headImageUrl]').val(data['headImageUrl']);
                            $('input[name=mobile]').val(data['mobile']);
                            $('input[name=idcardNumber]').val(data['idcardNumber']);
                            $('select[name=gender]').val(data['gender']);

                            $('input[name=headImageUrl]').attr("readOnly", true);
                            $('input[name=mobile]').attr("readOnly", true);
                            $('input[name=idcardNumber]').attr("readOnly", true);
                            $('select[name=gender]').attr("disabled", "disabled");

                        }
                    },
                    error: function () {
                        layer.msg('请求出错！！');
                    }
                });
            });
            $('button#send').click(function () {
                var coachName = $('input[name=coachName]').val();
                var upperLimit = $('input[name=upperLimit]').val();
                var idcardNumber = $('input[name=idcardNumber]').val();
                var mobile = $('input[name=mobile]').val();
                
                if (coachName == '' || coachName == null) {
                    layer.msg('教练名称不能为空!');
                    return false;
                } 
                if (mobile == '' || mobile == null) {
                    layer.msg('手机号不能为空!');
                    return false;
                }
                
                if (idcardNumber == '' || idcardNumber == null) {
                    layer.msg('身份证号不能为空!');
                    return false;
                } 
                if (upperLimit == '' || upperLimit == null) {
                    layer.msg('人数上限名称不能为空!');
                    return false;
                } 
                else {
                    $("#publicform").submit();
                }
            });

        });
    </script>
    <div class="wrap jj">
        <div class="common-form">
            <form id="publicform" method="post" class="form-horizontal J_ajaxForm" action="{:U('publicCourse/publicOpenPost')}">
                <input type="hidden" name='shopId' value='{$dateTime.shop_id}'/>
                <input type="hidden" name='day' value='{$dateTime.day}'/>
                <input type="hidden" name='clockTime' value='{$dateTime.clock_time}'/>
                <input type="hidden" name='flag' value='{$flag}'/>
                <fieldset>
                    <div class="control-group">
                        <label class="control-label">教练名称：</label>
                        <div class="controls">
                            <input type="text" class="input" name="coachName" value="{$public.coach_name}">
                            <input type="button" class="checkCoach btn" id="" value="搜索" />
                        </div>                                               
                    </div>
                    <div  id="checkCoachDiv" style="display:none;">
                        <!--                        <div class="control-group">
                                                    <label class="control-label">教练头像：</label>
                                                    <div class="controls">
                                                        <input id='' type="text" class="input" name="headImageUrl" value="" >    
                                                    </div>
                                                </div>-->
                        <div class="control-group">
                            <label class="control-label">性别:</label>
                            <div class="controls">
                                {:getEnumSelectWidget($gender,'gender',$coach['gender'])}
                            </div>
                        </div>
                        <div class="control-group">
                            <label class="control-label">手机号：</label>
                            <div class="controls">
                                <input id='mobile' type="text" class="input" name="mobile" value="{$coach.mobile}">    
                            </div>
                        </div>
                        <div class="control-group">
                            <label class="control-label">身份证号:</label>
                            <div class="controls">
                                <input type="text" class="input" name="idcardNumber" value="{$coach.idcard_number}">
                            </div>
                        </div> 
                       
                    </div>
                    <div class="control-group" id="courseTypeDiv" >
                        <div class="control-group"  >
                            <label class="control-label">公开课类型:</label>
                            <div class="controls">
                                {:getEnumSelectWidget($courseType,'courseType',$public['course_type'])}
                            </div>
                        </div>
                        <div class="control-group">
                            <label class="control-label">人数上限:</label>
                            <div class="controls">
                                <input type="text" class="input" name="upperLimit" value="15" readonly="true">
                            </div>
                        </div>
                    </div>
                </fieldset>
                <div class="form-actions">
                    <button  class="managetime btn" id="send">保存</button>
                </div>
            </form>
        </div>
    </div>    
    <script src="__ROOT__/statics/js/common.js"></script>
</body>
</html>